package net.kts.story.map;

import net.kts.story.StoryObjectHouse;
import net.kts.story.map.overlay.StorySelectMarkerOveray;
import android.graphics.drawable.Drawable;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class StoryTouchListener extends Overlay implements OnGestureListener{
	private GestureDetector gestureDetectorl;
	private MapView mapView;
	private StorySelectMarkerOveray selectMarkerOveray;
	private StoryObjectHouse storyObjectHouse;
	
	public StoryTouchListener(Drawable drawable, StoryObjectHouse storyObjectHouse) {
		super();
		this.storyObjectHouse = storyObjectHouse;
		this.gestureDetectorl = new GestureDetector(this);
		this.selectMarkerOveray = new StorySelectMarkerOveray(drawable);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event, MapView mapView) {
		this.mapView = mapView;
		return this.gestureDetectorl.onTouchEvent(event);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		return false;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {		
		GeoPoint geoPoint = this.mapView.getProjection().fromPixels((int)e.getX(), (int)e.getY());
		OverlayItem overlayItem = new OverlayItem(
				geoPoint, 
				"", 
				"");
		selectMarkerOveray.updateOverlay(overlayItem);
		this.mapView.getOverlays().add(2, selectMarkerOveray);
		
		storyObjectHouse.setSelectedLocation(geoPoint);
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
		storyObjectHouse.getStoryMenu().dismissMessageView();
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}
}
